import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle;

import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;
import java.util.Vector;
import javax.swing.BorderFactory;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JFrameReportes extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JTabbedPane jTabbedPaneReportes;
	private JPanel jPanelReporteCed;
	private JPanel jPanelReporteNotaF;
	private JTextField txtProm;
	private JLabel lblPromedio;
	private JTable jTableReprobados;
	private JScrollPane jScrollReprobados;
	private JTable jTableCedula;
	private JTable jTableAprobados;
	private JScrollPane jScrollAprobados;
	private JTable jTableNF;
	private JScrollPane jScrollReporteNF;
	private JScrollPane jScrollPaneNotaF;
	private JScrollPane jScrollCedula;
	private JPanel jPanelReprobados;
	private JPanel jPanelAprobados;
	private Seccion s = new Seccion();

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrameReportes inst = new JFrameReportes();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public JFrameReportes() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("Listado de Estudiantes");
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			{
				jTabbedPaneReportes = new JTabbedPane();
				getContentPane().add(jTabbedPaneReportes, BorderLayout.CENTER);
				jTabbedPaneReportes.setPreferredSize(new java.awt.Dimension(585, 268));
				{
					jPanelReporteCed = new JPanel();
					GroupLayout jPanelReporteCedLayout = new GroupLayout((JComponent)jPanelReporteCed);
					jPanelReporteCed.setLayout(jPanelReporteCedLayout);
					jTabbedPaneReportes.addTab("Ordenados Cedula", null, jPanelReporteCed, null);
					jPanelReporteCed.setPreferredSize(new java.awt.Dimension(524, 272));
					jPanelReporteCed.setBackground(new java.awt.Color(255,255,255));
					{
						jScrollCedula = new JScrollPane();
						{
							DefaultTableModel jTableCedulaModel  = new DefaultTableModel(
										new String[][] { { "", "" }, { "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" } },
										new String[] { "Cedula", "Nombre","Apellido" });
							
							jTableCedula = new JTable(jTableCedulaModel);
							jScrollCedula.setViewportView(jTableCedula);
							jTableCedula.setModel(jTableCedulaModel);
							
							s.EstudiantesOrdenadosCedula();
								
							int i =0;
							while(i<Seccion.estudiantes.size())
							{
								
								jTableCedula.setValueAt(Seccion.estudiantes.elementAt(i).getCedula(), i, 0);
								jTableCedula.setValueAt(Seccion.estudiantes.elementAt(i).getNombre(), i, 1);
								jTableCedula.setValueAt(Seccion.estudiantes.elementAt(i).getApellido(),i, 2);
								
								
								i++;
							}
							s.GuardarArchivo("Listado de Alumnos Ordenados por Cedula");
						}
					}
					jPanelReporteCedLayout.setHorizontalGroup(jPanelReporteCedLayout.createSequentialGroup()
						.addContainerGap(64, 64)
						.addComponent(jScrollCedula, 0, 404, Short.MAX_VALUE)
						.addContainerGap(98, 98));
					jPanelReporteCedLayout.setVerticalGroup(jPanelReporteCedLayout.createSequentialGroup()
						.addContainerGap(88, 88)
						.addComponent(jScrollCedula, 0, 232, Short.MAX_VALUE)
						.addContainerGap());
				}
				{
					jPanelReporteNotaF = new JPanel();
					GroupLayout jPanelReporteNotaFLayout = new GroupLayout((JComponent)jPanelReporteNotaF);
					jPanelReporteNotaF.setLayout(jPanelReporteNotaFLayout);
					jTabbedPaneReportes.addTab("Ordenado NotaF", null, jPanelReporteNotaF, null);
					jPanelReporteNotaF.setPreferredSize(new java.awt.Dimension(524, 272));
					jPanelReporteNotaF.setBackground(new java.awt.Color(255,255,255));
					{
						jScrollReporteNF = new JScrollPane();
						{
							TableModel jTableNFModel = new DefaultTableModel(new String[][] { { "","","",""},{ "","","",""}, { "","","",""}, { "","","",""},{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" } },
									new String[] { "Cedula", "Nombre", "Apellido", "Nota Final" });
							
							
							jTableNF = new JTable();
							jScrollReporteNF.setViewportView(jTableNF);
							jTableNF.setModel(jTableNFModel);
							jTableNF.setPreferredSize(new java.awt.Dimension(409, 167));

							s.listarNotaFinal();
							
							int i =0;
							while(i<Seccion.estudiantes.size())
							{
								
								jTableNF.setValueAt(Seccion.estudiantes.elementAt(i).getCedula(), i, 0);
								jTableNF.setValueAt(Seccion.estudiantes.elementAt(i).getNombre(), i, 1);
								jTableNF.setValueAt(Seccion.estudiantes.elementAt(i).getApellido(),i, 2);
								jTableNF.setValueAt(Seccion.estudiantes.elementAt(i).getNotaFinal(),i, 3); 
								
								i++;
							}
							s.GuardarArchivo("Listado de Alumnos Ordenados por Nota Final");
						}
					}
					{
						lblPromedio = new JLabel();
						lblPromedio.setText("Promedio de la seccion :");
						lblPromedio.setBackground(new java.awt.Color(191,191,191));
					}
					{
						txtProm = new JTextField();
						/*caja de texto de promedio de notas */
						txtProm.setText(String.valueOf(s.promedioNotasSeccionMenu()));
						txtProm.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
					}

					jPanelReporteNotaFLayout.setHorizontalGroup(jPanelReporteNotaFLayout.createSequentialGroup()
						.addContainerGap(55, 55)
						.addGroup(jPanelReporteNotaFLayout.createParallelGroup()
						    .addGroup(GroupLayout.Alignment.LEADING, jPanelReporteNotaFLayout.createSequentialGroup()
						        .addComponent(lblPromedio, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE)
						        .addComponent(txtProm, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
						        .addGap(0, 160, Short.MAX_VALUE))
						    .addGroup(GroupLayout.Alignment.LEADING, jPanelReporteNotaFLayout.createSequentialGroup()
						        .addPreferredGap(lblPromedio, jScrollReporteNF, LayoutStyle.ComponentPlacement.INDENT)
						        .addComponent(jScrollReporteNF, GroupLayout.PREFERRED_SIZE, 412, GroupLayout.PREFERRED_SIZE)
						        .addGap(0, 0, Short.MAX_VALUE)))
						.addContainerGap(84, 84));
					jPanelReporteNotaFLayout.setVerticalGroup(jPanelReporteNotaFLayout.createSequentialGroup()
						.addContainerGap(29, 29)
						.addGroup(jPanelReporteNotaFLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						    .addComponent(lblPromedio, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
						    .addComponent(txtProm, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGap(29)
						.addComponent(jScrollReporteNF, GroupLayout.PREFERRED_SIZE, 191, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(64, Short.MAX_VALUE));
				}
				{
					jPanelAprobados = new JPanel();
					GroupLayout jPanelAprobadosLayout = new GroupLayout((JComponent)jPanelAprobados);
					jPanelAprobados.setLayout(jPanelAprobadosLayout);
					jTabbedPaneReportes.addTab("Aprobados", null, jPanelAprobados, null);
					jPanelAprobados.setBackground(new java.awt.Color(255,255,255));
					{
						jScrollAprobados = new JScrollPane();
						{
							TableModel jTableAprobadosModel = 
								new DefaultTableModel(
										new String[][] { { "", "" }, { "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" } },
										new String[] { "Cedula", "Nombre", "Apellido", "Nota Final" });
							jTableAprobados = new JTable();
							jScrollAprobados.setViewportView(jTableAprobados);
							jTableAprobados.setModel(jTableAprobadosModel);
							jTableAprobados.setPreferredSize(new java.awt.Dimension(346, 160));

							int i =0;
							int j =0;
							while(i<Seccion.estudiantes.size() )
							{
								if(Seccion.estudiantes.elementAt(i).getEstatus() == "Aprobado")
								{
								jTableAprobados.setValueAt(Seccion.estudiantes.elementAt(i).getCedula(), j, 0);
								jTableAprobados.setValueAt(Seccion.estudiantes.elementAt(i).getNombre(), j, 1);
								jTableAprobados.setValueAt(Seccion.estudiantes.elementAt(i).getApellido(),j, 2);
								jTableAprobados.setValueAt(Seccion.estudiantes.elementAt(i).getNotaFinal(),j, 3); 
								j++;
								}
								i++;
							}
							s.GuardarArchivo("Listado de Alumnos Aprobados");
							
						}
					}
					jPanelAprobadosLayout.setHorizontalGroup(jPanelAprobadosLayout.createSequentialGroup()
						.addContainerGap(100, 100)
						.addComponent(jScrollAprobados, GroupLayout.PREFERRED_SIZE, 374, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(92, Short.MAX_VALUE));
					jPanelAprobadosLayout.setVerticalGroup(jPanelAprobadosLayout.createSequentialGroup()
						.addContainerGap(73, 73)
						.addComponent(jScrollAprobados, GroupLayout.PREFERRED_SIZE, 204, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(55, Short.MAX_VALUE));
				}
				{
					jPanelReprobados = new JPanel();
					GroupLayout jPanelReprobadosLayout = new GroupLayout((JComponent)jPanelReprobados);
					jPanelReprobados.setLayout(jPanelReprobadosLayout);
					jTabbedPaneReportes.addTab("Reprobados", null, jPanelReprobados, null);
					jPanelReprobados.setPreferredSize(new java.awt.Dimension(566, 289));
					jPanelReprobados.setBackground(new java.awt.Color(255,255,255));
					{
						jScrollReprobados = new JScrollPane();
						{
							TableModel jTableReprobadosModel = 
								new DefaultTableModel(
										new String[][] { { "", "" }, { "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" },{ "", "" } },
										new String[] { "Cedula", "Nombre", "Apellido", "Nota Final" });
							jTableReprobados = new JTable();
							jScrollReprobados.setViewportView(jTableReprobados);
							jTableReprobados.setModel(jTableReprobadosModel);
							
							int i =0;
							int j =0;
							while(i<Seccion.estudiantes.size() )
							{
								if(Seccion.estudiantes.elementAt(i).getEstatus() == "Reprobado")
								{
								jTableReprobados.setValueAt(Seccion.estudiantes.elementAt(i).getCedula(), j, 0);
								jTableReprobados.setValueAt(Seccion.estudiantes.elementAt(i).getNombre(), j, 1);
								jTableReprobados.setValueAt(Seccion.estudiantes.elementAt(i).getApellido(),j, 2);
								jTableReprobados.setValueAt(Seccion.estudiantes.elementAt(i).getNotaFinal(),j, 3); 
								j++;
								}
								i++;
							}
							s.GuardarArchivo("Listado de Alumnos Reprobados");
						}
					}

					jPanelReprobadosLayout.setHorizontalGroup(jPanelReprobadosLayout.createSequentialGroup()
						.addContainerGap(98, 98)
						.addComponent(jScrollReprobados, GroupLayout.PREFERRED_SIZE, 341, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(127, Short.MAX_VALUE));
					jPanelReprobadosLayout.setVerticalGroup(jPanelReprobadosLayout.createSequentialGroup()
						.addContainerGap(79, 79)
						.addComponent(jScrollReprobados, GroupLayout.PREFERRED_SIZE, 215, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(38, Short.MAX_VALUE));
				}
			}
			pack();
			this.setSize(581, 389);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
